<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="选择日期">
        <el-date-picker
          v-model="queryParams.beginDate"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="选择日期">
        </el-date-picker>至
        <el-date-picker
          v-model="queryParams.endDate"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="选择日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['affairs:cwDealPerDay:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>


    <template>
      <el-tabs v-model="activeName" type="card" @tab-click="handleClick">
        <el-tab-pane label="收入明细" name="first">
          <span>金额总计：{{this.cwDealPerDaySum.totalSum}}元</span><br>
          <el-row>
            <el-col :span="3"><div class="grid-content bg-purple">押金(总计)：{{this.cwDealPerDaySum.depositSum}}</div></el-col>
            <el-col :span="3"><div class="grid-content bg-purple-light">租金(总计)：{{this.cwDealPerDaySum.rentSum}}</div></el-col>
            <el-col :span="3"><div class="grid-content bg-purple">电费(总计)：{{this.cwDealPerDaySum.electricityFeeSum}}</div></el-col>
            <el-col :span="3"><div class="grid-content bg-purple-light">水费(总计)：{{this.cwDealPerDaySum.waterFeeSum}}</div></el-col>
            <el-col :span="3"><div class="grid-content bg-purple">款待(总计)：{{this.cwDealPerDaySum.netFeeSum}}</div></el-col>
            <el-col :span="3"><div class="grid-content bg-purple-light">燃气费(总计)：{{this.cwDealPerDaySum.gasFeeSum}}</div></el-col>
            <el-col :span="3"><div class="grid-content bg-purple-light">有线电视(总计)：{{this.cwDealPerDaySum.cableFeeSum}}</div></el-col>
            <el-col :span="3"><div class="grid-content bg-purple-light">其他(总计)：{{this.cwDealPerDaySum.otherFeeSum}}</div></el-col>
          </el-row>
          <el-table v-loading="loading" :data="cwDealPerDayList" @selection-change="handleSelectionChange">
            <el-table-column type="selection" width="55" align="center" />
            <el-table-column label="交易时间" align="center" prop="dealDate" width="180">
              <template slot-scope="scope">
                <span>{{ parseTime(scope.row.dealDate, '{y}-{m}-{d}') }}</span>
              </template>
            </el-table-column>
            <el-table-column label="总计（元）" align="center" prop="total" />
            <el-table-column label="押金（元）" align="center" prop="deposit" />
            <el-table-column label="租金（元）" align="center" prop="rent" />
            <el-table-column label="电费（元）" align="center" prop="electricityFee" />
            <el-table-column label="水费（元）" align="center" prop="waterFee" />
            <el-table-column label="宽带费（元）" align="center" prop="netFee" />
            <el-table-column label="燃气费（元）" align="center" prop="gasFee" />
            <el-table-column label="有线电视费（元）" align="center" prop="cableFee" />
            <el-table-column label="其他（元）" align="center" prop="otherFee" />
            <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
              <template slot-scope="scope">
                <el-button
                  size="mini"
                  type="text"
                  icon="el-icon-edit"
                  @click="handleUpdate(scope.row)"
                  v-hasPermi="['affairs:cwDealPerDay:edit']"
                >修改</el-button>
                <el-button
                  size="mini"
                  type="text"
                  icon="el-icon-delete"
                  @click="handleDelete(scope.row)"
                  v-hasPermi="['affairs:cwDealPerDay:remove']"
                >删除</el-button>
              </template>
            </el-table-column>
          </el-table>
          <pagination
            v-show="total>0"
            :total="total"
            :page.sync="queryParams.pageNum"
            :limit.sync="queryParams.pageSize"
            @pagination="getList"
          />
        </el-tab-pane>
        <el-tab-pane label="支出明细" name="second">
          <span>金额总计：{{this.cwDealPerDaySum.totalSum}}元</span><br>
          <el-row>
            <el-col :span="3"><div class="grid-content bg-purple">押金(总计)：{{this.cwDealPerDaySum.depositSum}}</div></el-col>
            <el-col :span="3"><div class="grid-content bg-purple-light">租金(总计)：{{this.cwDealPerDaySum.rentSum}}</div></el-col>
            <el-col :span="3"><div class="grid-content bg-purple">电费(总计)：{{this.cwDealPerDaySum.electricityFeeSum}}</div></el-col>
            <el-col :span="3"><div class="grid-content bg-purple-light">水费(总计)：{{this.cwDealPerDaySum.waterFeeSum}}</div></el-col>
            <el-col :span="3"><div class="grid-content bg-purple">款待(总计)：{{this.cwDealPerDaySum.netFeeSum}}</div></el-col>
            <el-col :span="3"><div class="grid-content bg-purple-light">燃气费(总计)：{{this.cwDealPerDaySum.gasFeeSum}}</div></el-col>
            <el-col :span="3"><div class="grid-content bg-purple-light">有线电视(总计)：{{this.cwDealPerDaySum.cableFeeSum}}</div></el-col>
            <el-col :span="3"><div class="grid-content bg-purple-light">其他(总计)：{{this.cwDealPerDaySum.otherFeeSum}}</div></el-col>
          </el-row>
          <el-table v-loading="loading" :data="cwDealPerDayList" @selection-change="handleSelectionChange">
            <el-table-column type="selection" width="55" align="center" />
            <el-table-column label="交易时间" align="center" prop="dealDate" width="180">
              <template slot-scope="scope">
                <span>{{ parseTime(scope.row.dealDate, '{y}-{m}-{d}') }}</span>
              </template>
            </el-table-column>
            <el-table-column label="总计（元）" align="center" prop="total" />
            <el-table-column label="押金（元）" align="center" prop="deposit" />
            <el-table-column label="租金（元）" align="center" prop="rent" />
            <el-table-column label="电费（元）" align="center" prop="electricityFee" />
            <el-table-column label="水费（元）" align="center" prop="waterFee" />
            <el-table-column label="宽带费（元）" align="center" prop="netFee" />
            <el-table-column label="燃气费（元）" align="center" prop="gasFee" />
            <el-table-column label="有线电视费（元）" align="center" prop="cableFee" />
            <el-table-column label="其他（元）" align="center" prop="otherFee" />
            <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
              <template slot-scope="scope">
                <el-button
                  size="mini"
                  type="text"
                  icon="el-icon-edit"
                  @click="handleUpdate(scope.row)"
                  v-hasPermi="['affairs:cwDealPerDay:edit']"
                >修改</el-button>
                <el-button
                  size="mini"
                  type="text"
                  icon="el-icon-delete"
                  @click="handleDelete(scope.row)"
                  v-hasPermi="['affairs:cwDealPerDay:remove']"
                >删除</el-button>
              </template>
            </el-table-column>
          </el-table>
          <pagination
            v-show="total>0"
            :total="total"
            :page.sync="queryParams.pageNum"
            :limit.sync="queryParams.pageSize"
            @pagination="getList"
          />
        </el-tab-pane>
      </el-tabs>
    </template>
  </div>
</template>

<script>
import { listCwDealPerDay, getCwDealPerDay, delCwDealPerDay, addCwDealPerDay, updateCwDealPerDay } from "@/api/affairs/cwDealPerDay";

export default {
  name: "CwDealPerDay",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 营业报表表格数据
      cwDealPerDayList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 左右两筐
      activeName: 'first',
      cwDealPerDaySum: {
        totalSum: null,
        depositSum: null,
        rentSum: null,
        electricityFeeSum: null,
        waterFeeSum: null,
        netFeeSum: null,
        gasFeeSum: null,
        cableFeeSum: null,
        otherFeeSum: null,
      },
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        businessId: null,
        beginDate: null,
        endDate: null,
        // 需要查询的收入/支出
        operationTypeDefault: 1,
        businessName: null,
        onlineFlg: null,
        dealDate: null,
        operationType: null,
        total: null,
        deposit: null,
        rent: null,
        electricityFee: null,
        waterFee: null,
        netFee: null,
        gasFee: null,
        cableFee: null,
        czFee: null,
        otherFee: null,
        reserve1: null,
        reserve2: null,
        reserve3: null,
        reserve4: null,
        reserve5: null,
        delFlg: null,
        createUserid: null,
        updateUserid: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        createTime: [
          { required: true, message: "创建时间不能为空", trigger: "blur" }
        ],
        updateTime: [
          { required: true, message: "更新时间不能为空", trigger: "blur" }
        ]
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    handleClick(tab, event) {
      //每次查询前都前往第一页
      this.queryParams.pageNum=1;
      //判断是哪个页面
      if (tab.name=="first"){
        //查询收入
        this.queryParams.operationTypeDefault=1;
      }else {
        //查询支出
        this.queryParams.operationTypeDefault=2;
      }
      this.getList();
      console.log(tab, event);
    },
    /** 查询营业报表列表 */
    getList() {
      this.loading = true;
      listCwDealPerDay(this.queryParams).then(response => {
        console.log(response);
        //列表
        this.cwDealPerDayList = response.list.rows;
        this.total = response.list.total;
        //数据总和
        this.cwDealPerDaySum=response.summation;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        businessId: null,
        businessName: null,
        onlineFlg: null,
        dealDate: null,
        operationType: null,
        total: null,
        deposit: null,
        rent: null,
        electricityFee: null,
        waterFee: null,
        netFee: null,
        gasFee: null,
        cableFee: null,
        czFee: null,
        otherFee: null,
        reserve1: null,
        reserve2: null,
        reserve3: null,
        reserve4: null,
        reserve5: null,
        delFlg: null,
        createUserid: null,
        createTime: null,
        updateUserid: null,
        updateTime: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加营业报表";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getCwDealPerDay(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改营业报表";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateCwDealPerDay(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addCwDealPerDay(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除营业报表编号为"' + ids + '"的数据项？').then(function() {
        return delCwDealPerDay(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('affairs/cwDealPerDay/export', {
        ...this.queryParams
      }, `cwDealPerDay_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
